<template>
  <div>
    <FormPanel
      ref="from"
      :list="formList"
      :cols="1"
      @formChange="changeHandle"
      :isSubmitBtn="false"
      labelWidth="80" />
    <div class="dialogBottmView" >
      <el-button @click="closeDrawer(1)">返 回</el-button>
      <el-button @click="closeDrawer(2)" :loading="loading" type="primary">保 存</el-button>
    </div>
  </div>
</template>

<script>
  import { dealwithHandle } from '@/api/customerService/demandes/register';
  export default {
    name: 'dealwith',
    props: {
      type: {
        type: String,
        default: 'add'
      },
      rowData: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      this.saveData=null;
      return{
        loading:false,
        formList: this.createTopFilterList(),
      };
    },
    created() {
      this.formList.find(item=>item.fieldName==='demandsNo').initialValue=this.rowData.demandsNo
    },
    methods:{
      closeDrawer(type){
        if(type==1){
          this.$emit('close')
        }else{
          const base=this.$refs.from.SUBMIT_FORM();
          this.rowData.remark=base.remark
          this.loading=true
          dealwithHandle(this.rowData).then(res=>{
            if (res.resultCode === 200) {
              this.$notify.success({title: '提示信息',message:'保存成功!'});
              // 重新加载
              this.loading=false
              this.$emit('close')
            }else {
              this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
              this.loading=false
              this.$emit('close')
            }
          })
        }
      },
      createTopFilterList(){
        return[
          {//3
            type: 'INPUT',
            label: '工单号',
            fieldName: 'demandsNo',
            initialValue: '',
            placeholder: '请输入',
            disabled: true
          },
          {
            type: 'TEXT_AREA',
            label: '备注内容',
            fieldName: 'remark',
            placeholder: '',
            initialValue: '',
            rules: [
              {
                required: true,
                message: '必填',
                trigger: 'change'
              }
            ]
          }
        ]
      },
      changeHandle(val) {
        this.saveData=val;
      },
    }
  };
</script>

<style scoped>

</style>
